package com.hengxinguotong.hxgtwygsp.ui.propertyService.report;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Quarter;
import com.hengxinguotong.hxgtwygsp.model.Year;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseTabFragment;
import com.hengxinguotong.hxgtwygsp.widget.DoubleListPW;
import com.hengxinguotong.hxgtwygsp.widget.QuarterPW;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 定期报告
 * Created by CS-Yong
 * 2019/8/8  16:41
 */
public class PeriodicReportFragment extends BaseTabFragment implements DoubleListPW.OnClickCallback<Year, Quarter> {


    @BindView(R.id.report_quarter)
    TextView mReportQuarter;
    @BindView(R.id.report_quarter_container)
    RelativeLayout mReportQuarterContainer;

    private List<Year> yearList;

    @Inject
    public PeriodicReportFragment() {
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_periodic_report_fragment;
    }

    @Override
    public void init() {
        yearList = new ArrayList<>();
        String[] quarters = getResources().getStringArray(R.array.array_quarter);
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH);
        int quarterValue = month / 3;
        mReportQuarter.setText(getString(R.string.patrol_quarter, calendar.get(Calendar.YEAR), quarters[quarterValue]));
        Year year;
        List<Quarter> quarterList;
        Quarter quarter;
        for (int i = 0; i < 3; i++) {
            year = new Year();
            year.setName(getString(R.string.patrol_year, calendar.get(Calendar.YEAR)));
            year.setValue(calendar.get(Calendar.YEAR));
            quarterList = new ArrayList<>();
            for (int j = 0; j <= quarterValue; j++) {
                quarter = new Quarter();
                quarter.setValue(j);
                quarter.setName(quarters[j]);
                quarterList.add(quarter);
            }
            year.setQuarterList(quarterList);
            yearList.add(year);
            calendar.add(Calendar.YEAR, -1);
            quarterValue = 3;
        }
    }


    @OnClick(R.id.report_quarter_container)
    public void onViewClicked(View view) {
        QuarterPW quarterPW = new QuarterPW(getContext(), view.getWidth());
        quarterPW.setOnClickCallback(this);
        quarterPW.initData(yearList);
        quarterPW.showAsDropDown(view);
    }

    @Override
    public void onClickPW(Year year, Quarter quarter) {
        mReportQuarter.setText(getString(R.string.patrol_quarter, year.getValue(), quarter.getName()));
    }

}
